package net.halflite.mzkr.action;

import javax.annotation.Resource;

import net.halflite.mzkr.service.RegistedUserService;

import org.apache.struts.action.ActionMessages;
import org.seasar.struts.annotation.Arg;
import org.seasar.struts.annotation.EmailType;
import org.seasar.struts.annotation.Execute;
import org.seasar.struts.annotation.Mask;
import org.seasar.struts.annotation.Msg;
import org.seasar.struts.annotation.Required;
import org.seasar.struts.enums.SaveType;

/** パスワード再発行用アクションクラス */
public class ReissueAction {

	@Resource
	private RegistedUserService registedUserService;

	/** メールアドレス */
	@Required(arg0 = @Arg(key = "メールアドレス", resource = false))
	@Mask(mask = "^\\S+$", msg = @Msg(key = "errors.include.space"),
			arg0 = @Arg(key = "入力したメールアドレス", resource = false))
	@EmailType(arg0 = @Arg(key = "入力したメールアドレス", resource = false))
	public String address;

	/** メールアドレス入力 */
    @Execute(validator = false)
    public String password() {
        return "password.jsp";
    }

    /** パスワード再発行メール送信処理 */
    @Execute(validate = "validate", saveErrors = SaveType.SESSION, input = "password?redirect=true")
    public String post() {
    	registedUserService.reissuePasswordMail(address);
        return "success?redirect=true";
    }

    /** パスワード再発行メール送信完了 */
    @Execute(validator = false)
    public String success() {
        return "success.jsp";
    }
    
    /** メールアドレス検証 */
    public ActionMessages validate() {
    	return registedUserService.validateReissuePasswordAddress(address);
    }
}
